﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BankImplementation
{
    class Bank
    {
        private List<Account> accounts = new List<Account>();

        public void CreateAccount(decimal money)
        {
            Account account = new Account();
            account.GetId();
            account.GetSetMoney = money;
            accounts.Add(account);
            Console.WriteLine("Your ID: {0}. Current balance {1}", account.GetId(), account.GetSetMoney);
        }

        public void AddMoneyToAccount(int id, decimal money)
        {
            Account account = new Account();
            for (int i = 0; i < accounts.Count; i++)
            {
                if (accounts[i].GetId() == id)
                {
                    accounts[i].GetSetMoney = money;
                    Console.WriteLine("The account was credited by {0}. Current balance {1}", money, accounts[i].GetSetMoney);
                }
                else
                {
                    Console.WriteLine("Account isn't found");
                }
            }
        }

        public void GiveMoneyFromAccount(int id, decimal money)
        {
            for (int i = 0; i < accounts.Count; i++)
            {
                if (accounts[i].GetId() == id)
                {
                    accounts[i].GiveMoney = money;
                    Console.WriteLine("From your account was withdrawn {0}. Current balance {1}", money, accounts[i].GetSetMoney);
                }
                else
                {
                    Console.WriteLine("Account isn't found");
                }
            }
        }

        public void GetAccountBalance(int id)
        {
            for (int i = 0; i < accounts.Count; i++)
            {
                if (accounts[i].GetId() == id)
                {
                    Console.WriteLine("Current balance: {0}", accounts[i].GetSetMoney);
                }
                else
                {
                    Console.WriteLine("Account isn't found");
                }
            }
        }

        public decimal CloseAccount(int id)
        {
            for (int i = 0; i < accounts.Count; i++)
            {
                if (accounts[i].GetId() == id)
                {
                    decimal money = accounts[i].GiveMoney;
                    Console.WriteLine("Account {0} was removed. From your account was withdrawn {1}.", accounts[i].GetId(), money);
                    accounts.Remove(accounts[i]);
                    return money;
                }
                else
                {
                    Console.WriteLine("Account isn't found");
                }
            }
            return 0;
        }
    }
}
